<template>
  <view class="tree-node">
    <view class="node-content">
      <text class="node-name">{{ member.firstName }}{{ member.lastName }}</text>
      <text class="node-tag">{{ member.relation }}</text>
      <text v-if="member.isSelf" class="node-tag">本人</text>
    </view>
    <view v-if="children.length" class="node-children">
      <FamilyTreeNode
        v-for="child in children"
        :key="child.id"
        :member="child"
        :all-members="allMembers"
      />
    </view>
  </view>
</template>

<script>
export default {
  name: "FamilyTreeNode",
  props: {
    member: Object,
    allMembers: Array,
  },
  computed: {
    children() {
      return this.allMembers.filter((m) => m.parentId === this.member.id);
    },
  },
};
</script>

<style scoped>
.tree-node {
  margin-left: 20px;
  border-left: 1px dashed #ccc;
  padding-left: 10px;
}
.node-content {
  margin-bottom: 4px;
}
.node-name {
  font-weight: bold;
  color: #409eff;
}
.node-tag {
  margin-left: 8px;
  color: #999;
  font-size: 12px;
}
.node-children {
  margin-top: 2px;
}
</style>
